import { _decorator, Component, Node, Vec3 } from 'cc';
import { TankManager } from './TankManager';
const { ccclass, property } = _decorator;

@ccclass('ExplosionManager')
export class ExplosionManager {
    private static instance: ExplosionManager = null;

    private constructor() { }

    tanks: TankManager[];

    public static getInstance() {
        if (this.instance == null) {
            this.instance = new ExplosionManager();
        }
        return this.instance;
    }

    public judgeExplosionHurt(nodePos: Vec3, radius: number): TankManager[] {
        const tanksInRange: TankManager[] = [];
        for (const tank of this.tanks) {
            const tankWorldPos = tank.instance.worldPosition; // 假设 Tank 类有一个 node 属性
            const dx = tankWorldPos.x - nodePos.x;
            const dz = tankWorldPos.z - nodePos.z;
            const distanceSquared = dx * dx + dz * dz;
            if (distanceSquared <= radius * radius) {
                tanksInRange.push(tank);
            }
        }
        return tanksInRange;
    }
}

